<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">



  <meta name="description" content="Android Studio Git使用"/>




  <meta name="keywords" content="git的使用, 金色的大海" />










  <link rel="alternate" href="/blog/default" title="金色的大海">




  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=2.9.0" />



<link rel="canonical" href="http://jy4416.gitee.io/blog/2020/04/15/asgit/"/>



  <link rel="stylesheet" type="text/css" href="/blog/lib/fancybox/jquery.fancybox.css" />




  <link rel="stylesheet" type="text/css" href="/blog/lib/nprogress/nprogress.min.css" />



<link rel="stylesheet" type="text/css" href="/blog/css/style.css?v=2.9.0" />



  



  <script id="baidu_push">
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>








<script>
  window.config = {"title":"金色的大海","subtitle":"","description":"","author":"jy","language":"zh-cn","timezone":"","url":"http://jy4416.gitee.io/blog","root":"/blog/","permalink":":year/:month/:day/:title/","permalink_defaults":null,"pretty_urls":{"trailing_index":true,"trailing_html":true},"source_dir":"source","public_dir":"public","tag_dir":"tags","archive_dir":"archives","category_dir":"categories","code_dir":"downloads/code","i18n_dir":":lang","skip_render":null,"new_post_name":":title.md","default_layout":"post","titlecase":false,"external_link":{"enable":true,"field":"site","exclude":""},"filename_case":0,"render_drafts":false,"post_asset_folder":true,"relative_link":false,"future":true,"highlight":{"enable":true,"auto_detect":false,"line_number":true,"tab_replace":"","wrap":true,"hljs":false},"default_category":"uncategorized","category_map":null,"tag_map":null,"date_format":"YYYY-MM-DD","time_format":"HH:mm:ss","use_date_for_updated":false,"per_page":10,"pagination_dir":"page","theme":"hexo-theme-even","server":{"port":4000,"log":false,"compress":false,"header":true,"cache":false},"deploy":{"type":"git","repo":"https://gitee.com/j4416/blog.git","branch":"master"},"ignore":null,"meta_generator":true,"keywords":null,"index_generator":{"per_page":10,"order_by":"-date","path":""},"include":null,"exclude":null,"category_generator":{"per_page":10},"archive_generator":{"per_page":10,"yearly":true,"monthly":true,"daily":false},"marked":{"gfm":true,"pedantic":false,"breaks":true,"smartLists":true,"smartypants":true,"modifyAnchors":"","autolink":true,"sanitizeUrl":false,"headerIds":true},"tag_generator":{"per_page":10},"since":2020,"favicon":"/favicon.ico","rss":"default","menu":{"Home":"/","Archives":"/archives/","Tags":"/tags","Categories":"/categories","About":"/about"},"color":"Default","toc":true,"fancybox":true,"pjax":true,"copyright":{"enable":true,"license":"<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\" target=\"_blank\">知识共享署名-非商业性使用 4.0 国际许可协议</a>"},"reward":{"enable":false,"qrCode":{"wechat":null,"alipay":null}},"social":{"email":"jy4416@aliyun.com","stack-overflow":null,"twitter":null,"facebook":null,"linkedin":null,"google":null,"github":"https://github.com/jy4416","weibo":null,"zhihu":null,"douban":null,"pocket":null,"tumblr":null,"instagram":null},"leancloud":{"app_id":null,"app_key":null},"baidu_analytics":null,"baidu_verification":null,"google_analytics":null,"google_verification":null,"disqus_shortname":null,"changyan":{"appid":null,"appkey":null},"livere_datauid":null,"version":"2.9.0"};
</script>

    <title> Android Studio Git使用 - 金色的大海 </title>
  <meta name="generator" content="Hexo 4.2.0"></head>

  <body><div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/blog/." class="logo">金色的大海</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>

<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    
      <a href="/blog/">
        <li class="mobile-menu-item">
          
          
            首页
          
        </li>
      </a>
    
      <a href="/blog/archives/">
        <li class="mobile-menu-item">
          
          
            归档
          
        </li>
      </a>
    
      <a href="/blog/tags">
        <li class="mobile-menu-item">
          
          
            标签
          
        </li>
      </a>
    
      <a href="/blog/categories">
        <li class="mobile-menu-item">
          
          
            分类
          
        </li>
      </a>
    
      <a href="/blog/about">
        <li class="mobile-menu-item">
          
          
            关于
          
        </li>
      </a>
    
  </ul>
</nav>

    <div class="container" id="mobile-panel">
      <header id="header" class="header"><div class="logo-wrapper">
  <a href="/blog/." class="logo">金色的大海</a>
</div>

<nav class="site-navbar">
  
    <ul id="menu" class="menu">
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/">
            
            
              首页
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/archives/">
            
            
              归档
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/tags">
            
            
              标签
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/categories">
            
            
              分类
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/about">
            
            
              关于
            
          </a>
        </li>
      
    </ul>
  
</nav>

      </header>

      <main id="main" class="main">
        <div class="content-wrapper">
          <div id="content" class="content">
            
  
  <article class="post">
    <header class="post-header">
      <h1 class="post-title">
        
          Android Studio Git使用
        
      </h1>

      <div class="post-meta">
        <span class="post-time">
          2020-04-15
        </span>
        
          <div class="post-category">
            
              <a href="/blog/categories/Git/">Git</a>
            
          </div>
        
        
      </div>
    </header>

    
    
  <div class="post-toc" id="post-toc">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#一、准备"><span class="toc-text">一、准备</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Git安装"><span class="toc-text">Git安装</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#官网地址"><span class="toc-text">官网地址</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#在AndroidStudio中配置Git"><span class="toc-text">在AndroidStudio中配置Git</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#配置Git"><span class="toc-text">配置Git</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#二、从远程Git库中克隆代码"><span class="toc-text">二、从远程Git库中克隆代码</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#新建项目"><span class="toc-text">新建项目</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#设置远程库地址"><span class="toc-text">设置远程库地址</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#三、Git的使用"><span class="toc-text">三、Git的使用</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Git提交"><span class="toc-text">Git提交</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Git推送"><span class="toc-text">Git推送</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Git拉取"><span class="toc-text">Git拉取</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#四、Git冲突解决"><span class="toc-text">四、Git冲突解决</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#拉取代码冲突"><span class="toc-text">拉取代码冲突</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-提交本地"><span class="toc-text">1.提交本地</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-拉取代码"><span class="toc-text">2.拉取代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-合并代码"><span class="toc-text">3.合并代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-重新提交代码"><span class="toc-text">4.重新提交代码</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#提交时代码冲突"><span class="toc-text">提交时代码冲突</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-提交代码"><span class="toc-text">1.提交代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-合并代码"><span class="toc-text">2.合并代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-推送代码"><span class="toc-text">3.推送代码</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#五、本地推送代码到远程Git库"><span class="toc-text">五、本地推送代码到远程Git库</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#创建本地Git版本库"><span class="toc-text">创建本地Git版本库</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#新建项目-1"><span class="toc-text">新建项目</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#项目添加到Git库"><span class="toc-text">项目添加到Git库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#添加忽略文件"><span class="toc-text">添加忽略文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#代码添加到版本库"><span class="toc-text">代码添加到版本库</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#将代码推送到远程库中"><span class="toc-text">将代码推送到远程库中</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#设置远程代码库"><span class="toc-text">设置远程代码库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#代码推送到远程库"><span class="toc-text">代码推送到远程库</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#六、Git分支的使用"><span class="toc-text">六、Git分支的使用</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#创建分支"><span class="toc-text">创建分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#本地分支提交到远程分支"><span class="toc-text">本地分支提交到远程分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#分支切换"><span class="toc-text">分支切换</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#分支比较"><span class="toc-text">分支比较</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#分支合并"><span class="toc-text">分支合并</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#分支删除"><span class="toc-text">分支删除</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#七、回退到某个版本"><span class="toc-text">七、回退到某个版本</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Mixed方式"><span class="toc-text">Mixed方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Soft方式"><span class="toc-text">Soft方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Hard方式"><span class="toc-text">Hard方式</span></a></li></ol></li></ol>
    </div>
  </div>



    <div class="post-content">
      
        <h1 id="一、准备"><a href="#一、准备" class="headerlink" title="一、准备"></a>一、准备</h1><h2 id="Git安装"><a href="#Git安装" class="headerlink" title="Git安装"></a>Git安装</h2><h3 id="官网地址"><a href="#官网地址" class="headerlink" title="官网地址"></a>官网地址</h3><p><a href="https://gitforwindows.org/" target="_blank" rel="noopener">https://gitforwindows.org/</a></p>
<h2 id="在AndroidStudio中配置Git"><a href="#在AndroidStudio中配置Git" class="headerlink" title="在AndroidStudio中配置Git"></a>在AndroidStudio中配置Git</h2><h3 id="配置Git"><a href="#配置Git" class="headerlink" title="配置Git"></a>配置Git</h3><p>在AndroidStudio中打开【File】—&gt;【Settings】</p>
<p><img src="/blog/2020/04/15/asgit/01.png" alt></p>
<h1 id="二、从远程Git库中克隆代码"><a href="#二、从远程Git库中克隆代码" class="headerlink" title="二、从远程Git库中克隆代码"></a>二、从远程Git库中克隆代码</h1><p>从远程Git库中clone代码到本地</p>
<a id="more"></a>

<h2 id="新建项目"><a href="#新建项目" class="headerlink" title="新建项目"></a>新建项目</h2><p><img src="/blog/2020/04/15/asgit/11.png" alt></p>
<h2 id="设置远程库地址"><a href="#设置远程库地址" class="headerlink" title="设置远程库地址"></a>设置远程库地址</h2><p><img src="/blog/2020/04/15/asgit/12.png" alt></p>
<h1 id="三、Git的使用"><a href="#三、Git的使用" class="headerlink" title="三、Git的使用"></a>三、Git的使用</h1><p>首先通过add将需要管理的代码文件添加到Git库中，然后通过commit提交到本地库，再通过push推送到远程</p>
<p><img src="/blog/2020/04/15/asgit/13.png" alt></p>
<h2 id="Git提交"><a href="#Git提交" class="headerlink" title="Git提交"></a>Git提交</h2><p>commit提交代码到本地Git库</p>
<p><img src="/blog/2020/04/15/asgit/14.png" alt></p>
<h2 id="Git推送"><a href="#Git推送" class="headerlink" title="Git推送"></a>Git推送</h2><p>push推送本地代码库到Git远程服务器</p>
<p><img src="/blog/2020/04/15/asgit/15.png" alt></p>
<h2 id="Git拉取"><a href="#Git拉取" class="headerlink" title="Git拉取"></a>Git拉取</h2><p>pull从远程服务器中拉取代码到本地</p>
<p><img src="/blog/2020/04/15/asgit/16.png" alt></p>
<p><img src="/blog/2020/04/15/asgit/17.png" alt></p>
<h1 id="四、Git冲突解决"><a href="#四、Git冲突解决" class="headerlink" title="四、Git冲突解决"></a>四、Git冲突解决</h1><p>如果有2人以上修改同一个文件，在推送或下拉时会提示代码冲突。</p>
<h2 id="拉取代码冲突"><a href="#拉取代码冲突" class="headerlink" title="拉取代码冲突"></a>拉取代码冲突</h2><p>拉取（pull)代码时产生冲突</p>
<p><img src="/blog/2020/04/15/asgit/18.png" alt></p>
<h3 id="1-提交本地"><a href="#1-提交本地" class="headerlink" title="1.提交本地"></a>1.提交本地</h3><p>首先将冲突的文件提交到本地（commit)</p>
<p><img src="/blog/2020/04/15/asgit/19.png" alt></p>
<h3 id="2-拉取代码"><a href="#2-拉取代码" class="headerlink" title="2.拉取代码"></a>2.拉取代码</h3><p>然后再拉取远程的代码（pull)</p>
<p><img src="/blog/2020/04/15/asgit/20.png" alt></p>
<h3 id="3-合并代码"><a href="#3-合并代码" class="headerlink" title="3.合并代码"></a>3.合并代码</h3><p>拉取后会出现代码合并界面，在此界面可以保留本地代码，或保留远程代码，或者两个合并。</p>
<p><img src="/blog/2020/04/15/asgit/21.png" alt></p>
<p><img src="/blog/2020/04/15/asgit/22.png" alt></p>
<h3 id="4-重新提交代码"><a href="#4-重新提交代码" class="headerlink" title="4.重新提交代码"></a>4.重新提交代码</h3><p>解决冲突后一定要重新提交冲突的文件。</p>
<p>提交到本地</p>
<p><img src="/blog/2020/04/15/asgit/23.png" alt></p>
<p>推送到远程</p>
<p><img src="/blog/2020/04/15/asgit/24.png" alt></p>
<h2 id="提交时代码冲突"><a href="#提交时代码冲突" class="headerlink" title="提交时代码冲突"></a>提交时代码冲突</h2><h3 id="1-提交代码"><a href="#1-提交代码" class="headerlink" title="1.提交代码"></a>1.提交代码</h3><p>提交(push)代码产生冲突时会弹出合并界面提示合并代码。</p>
<p><img src="/blog/2020/04/15/asgit/25.png" alt></p>
<h3 id="2-合并代码"><a href="#2-合并代码" class="headerlink" title="2.合并代码"></a>2.合并代码</h3><p>点击合并按钮，可以接受本地代码，或接受远程代码，或合并代码。</p>
<p><img src="/blog/2020/04/15/asgit/27.png" alt></p>
<h3 id="3-推送代码"><a href="#3-推送代码" class="headerlink" title="3.推送代码"></a>3.推送代码</h3><p>解决冲突后一定要将冲突的文件推送到远程服务器。</p>
<p>将合并后的代码推送到远程服务器。</p>
<p><img src="/blog/2020/04/15/asgit/28.png" alt></p>
<p><img src="/blog/2020/04/15/asgit/29.png" alt></p>
<h1 id="五、本地推送代码到远程Git库"><a href="#五、本地推送代码到远程Git库" class="headerlink" title="五、本地推送代码到远程Git库"></a>五、本地推送代码到远程Git库</h1><h2 id="创建本地Git版本库"><a href="#创建本地Git版本库" class="headerlink" title="创建本地Git版本库"></a>创建本地Git版本库</h2><h3 id="新建项目-1"><a href="#新建项目-1" class="headerlink" title="新建项目"></a>新建项目</h3><p>新建一个本地Android项目</p>
<h3 id="项目添加到Git库"><a href="#项目添加到Git库" class="headerlink" title="项目添加到Git库"></a>项目添加到Git库</h3><p>点击工具栏【VCS】</p>
<p><img src="/blog/2020/04/15/asgit/02.png" alt></p>
<p>选择Git</p>
<p><img src="/blog/2020/04/15/asgit/03.png" alt></p>
<h3 id="添加忽略文件"><a href="#添加忽略文件" class="headerlink" title="添加忽略文件"></a>添加忽略文件</h3><p>使用AndroidStudio创建项目后，会在项目目录下和Module目录下自动生成.gitignore文件，这就是git的忽略文件。可以将不需要代码库管理的文件在此文件设置。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">*.iml</span><br><span class="line">*.apk</span><br><span class="line">.gradle</span><br><span class="line">.idea</span><br><span class="line">/gradlew</span><br><span class="line">/gradlew.bat</span><br><span class="line">/local.properties</span><br><span class="line">/.idea/workspace.xml</span><br><span class="line">/.idea/libraries</span><br><span class="line">.DS_Store</span><br><span class="line">/build</span><br><span class="line">/captures</span><br><span class="line">.externalNativeBuild</span><br></pre></td></tr></table></figure>

<h3 id="代码添加到版本库"><a href="#代码添加到版本库" class="headerlink" title="代码添加到版本库"></a>代码添加到版本库</h3><p><img src="/blog/2020/04/15/asgit/04.png" alt></p>
<p><img src="/blog/2020/04/15/asgit/05.png" alt></p>
<h2 id="将代码推送到远程库中"><a href="#将代码推送到远程库中" class="headerlink" title="将代码推送到远程库中"></a>将代码推送到远程库中</h2><h3 id="设置远程代码库"><a href="#设置远程代码库" class="headerlink" title="设置远程代码库"></a>设置远程代码库</h3><p><img src="/blog/2020/04/15/asgit/06.png" alt></p>
<p><img src="/blog/2020/04/15/asgit/07.png" alt></p>
<h3 id="代码推送到远程库"><a href="#代码推送到远程库" class="headerlink" title="代码推送到远程库"></a>代码推送到远程库</h3><p><img src="/blog/2020/04/15/asgit/08.png" alt></p>
<p><img src="/blog/2020/04/15/asgit/10.png" alt></p>
<h1 id="六、Git分支的使用"><a href="#六、Git分支的使用" class="headerlink" title="六、Git分支的使用"></a>六、Git分支的使用</h1><h2 id="创建分支"><a href="#创建分支" class="headerlink" title="创建分支"></a>创建分支</h2><p>Git菜单</p>
<p><img src="/blog/2020/04/15/asgit/30.png" alt></p>
<p>选择【New Branch】</p>
<p><img src="/blog/2020/04/15/asgit/31.png" alt></p>
<p>输入分支的名称</p>
<p><img src="/blog/2020/04/15/asgit/32.png" alt></p>
<p>在Android Studio的右下角可以查看当前的分支</p>
<p><img src="/blog/2020/04/15/asgit/33.png" alt></p>
<h2 id="本地分支提交到远程分支"><a href="#本地分支提交到远程分支" class="headerlink" title="本地分支提交到远程分支"></a>本地分支提交到远程分支</h2><p>提交</p>
<p><img src="/blog/2020/04/15/asgit/34.png" alt></p>
<p>推送</p>
<p><img src="/blog/2020/04/15/asgit/35.png" alt></p>
<h2 id="分支切换"><a href="#分支切换" class="headerlink" title="分支切换"></a>分支切换</h2><p>切换后可以查看右下角的分支名称</p>
<p><img src="/blog/2020/04/15/asgit/36.png" alt></p>
<h2 id="分支比较"><a href="#分支比较" class="headerlink" title="分支比较"></a>分支比较</h2><p><img src="/blog/2020/04/15/asgit/38.png" alt></p>
<p><img src="/blog/2020/04/15/asgit/39.png" alt></p>
<h2 id="分支合并"><a href="#分支合并" class="headerlink" title="分支合并"></a>分支合并</h2><p>将分支内容合并到master分支中</p>
<p><img src="/blog/2020/04/15/asgit/40.png" alt></p>
<h2 id="分支删除"><a href="#分支删除" class="headerlink" title="分支删除"></a>分支删除</h2><p><img src="/blog/2020/04/15/asgit/41.png" alt></p>
<h1 id="七、回退到某个版本"><a href="#七、回退到某个版本" class="headerlink" title="七、回退到某个版本"></a>七、回退到某个版本</h1><p><img src="/blog/2020/04/15/asgit/42.png" alt></p>
<ol>
<li><p>git reset –mixed：此为默认方式，不带任何参数的git reset，即时这种方式，它回退到某个版本，只保留源码，回退commit和index信息。</p>
</li>
<li><p>git reset –soft：回退到某个版本，只回退了commit的信息，不会恢复到index file一级。如果还要提交，直接commit即可。</p>
</li>
<li><p>git reset –hard：彻底回退到某个版本，本地的源码也会变为上一个版本的内容，此命令 慎用！<br>注意：选择hard时，先把当前的版本提交一下。</p>
</li>
<li><p>to commit填：HEAD，‘HEAD<del>1’表示HEAD的前一个版本，‘HEAD</del>2’依次类推。点击Validate可以查看提交。</p>
<p>注意：这些回滚只影响本地Git库内容</p>
</li>
</ol>
<p><img src="/blog/2020/04/15/asgit/43.png" alt></p>
<h2 id="Mixed方式"><a href="#Mixed方式" class="headerlink" title="Mixed方式"></a>Mixed方式</h2><p>新建一个A.java文件提交并推送到远程</p>
<p><img src="/blog/2020/04/15/asgit/44.png" alt></p>
<p>回滚最后一个commit,选择Mixed</p>
<p><img src="/blog/2020/04/15/asgit/45.png" alt></p>
<p>index回退，commit回退</p>
<p><img src="/blog/2020/04/15/asgit/46.png" alt></p>
<h2 id="Soft方式"><a href="#Soft方式" class="headerlink" title="Soft方式"></a>Soft方式</h2><p>回滚最后一个commit,选择Soft</p>
<p><img src="/blog/2020/04/15/asgit/47.png" alt></p>
<p>commit回退</p>
<p><img src="/blog/2020/04/15/asgit/48.png" alt></p>
<h2 id="Hard方式"><a href="#Hard方式" class="headerlink" title="Hard方式"></a>Hard方式</h2><p>彻底回退到某个版本，本地的源码也会变为上一个版本的内容，</p>
<p><img src="/blog/2020/04/15/asgit/49.png" alt></p>
<p>彻底回到前一个版本</p>
<p><img src="/blog/2020/04/15/asgit/50.png" alt></p>

      
    </div>

    
      
      

  <div class="post-copyright">
    <p class="copyright-item">
      <span>原文作者: </span>
      <a href="http://jy4416.gitee.io/blog">jy</a>
    </p>
    <p class="copyright-item">
      <span>原文链接: </span>
      <a href="http://jy4416.gitee.io/blog/2020/04/15/asgit/">http://jy4416.gitee.io/blog/2020/04/15/asgit/</a>
    </p>
    <p class="copyright-item">
      <span>许可协议: </span>
      
      <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank">知识共享署名-非商业性使用 4.0 国际许可协议</a>
    </p>
  </div>



      
      
    

    
      <footer class="post-footer">
        
          <div class="post-tags">
            
              <a href="/blog/tags/git%E7%9A%84%E4%BD%BF%E7%94%A8/">git的使用</a>
            
          </div>
        
        
        
  <nav class="post-nav">
    
      <a class="prev" href="/blog/2020/04/15/eclipse-git/">
        <i class="iconfont icon-left"></i>
        <span class="prev-text nav-default">Eclipse中Git的使用</span>
        <span class="prev-text nav-mobile">上一篇</span>
      </a>
    
    
      <a class="next" href="/blog/2020/04/14/vuex/">
        <span class="next-text nav-default">Vuex案例</span>
        <span class="prev-text nav-mobile">下一篇</span>
        <i class="iconfont icon-right"></i>
      </a>
    
  </nav>

      </footer>
    

  </article>


          </div>
          
  <div class="comments" id="comments">
    
  </div>


        </div>
      </main>

      <footer id="footer" class="footer">

  <div class="social-links">
    
      
        
          <a href="mailto:jy4416@aliyun.com" class="iconfont icon-email" title="email"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
        
          <a href="https://github.com/jy4416" target="_blank" rel="noopener" class="iconfont icon-github" title="github"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
    
    
    
      
      <a href="/blog/atom.xml" class="iconfont icon-rss" title="rss"></a>
    
  </div>


<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/ahonn/hexo-theme-even" target="_blank" rel="noopener">Even</a>
  </span>

  <span class="copyright-year">
    
    &copy; 
    
    2020

    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">jy</span>
  </span>
</div>

      </footer>

      <div class="back-to-top" id="back-to-top">
        <i class="iconfont icon-up"></i>
      </div>
    </div>

    
  
  

  



    
  



  
  





  
    <script type="text/javascript" src="/blog/lib/jquery/jquery.min.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/slideout/slideout.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/fancybox/jquery.fancybox.pack.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/pjax/jquery.pjax.min.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/nprogress/nprogress.min.js"></script>
  


    <script type="text/javascript" src="/blog/js/src/even.js?v=2.9.0"></script>

  </body>
</html>
